//四种请求参数的解析
//id:,?name='fumei'

const Koa=require('koa');

const app=new Koa();
const log=console.log;
const Router=require('koa-router');
const router=new Router;
const bodyParser = require('koa-bodyparser');


router.get('/api/tasks/',async(ctx,next)=>{
    let {page,limit}=ctx.query;
    log(ctx.headers['user-agent']);
    log(`得到代办事项列表',page=${page},limit=${limit}`);
        ctx.body='查询成功';
    
})

router.post('/api/tasks/',async(ctx,next)=>{
    let {task}=ctx.request.body;
    log(`添加代办事项列表,task=${task}`);
    ctx.body='添加成功';
})
router.put('/api/tasks/:id',async(ctx,next)=>{
    let {id}=ctx.params;
    let {task}=ctx.request.body;
    log(`修改代办事项列表,id=${id},task=${task}`);
    ctx.body='修改成功';
   
    
})
router.delete('/api/tasks/:id',async(ctx,next)=>{
    let {id}=ctx.params;
    log(`删除代办事项列表,id=${id}`);
    ctx.body='删除成功';
})

app.use(bodyParser({enableTypes:['json','text','form']}))
app.use(router.routes());

app.listen(8080);